﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="_20160627AJAX项目学习._03无刷新评论功能.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script src="../Js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("# BtnPost").click(function () {
                $.post("PostComment.ashx", { "msg": $("#TxtComment").val() }, function (data, status) {
                    if (status != "success") {
                        alert("发表评论失败,请重试！");
                        return;
                    } if (data == "ok") {
                        var newComment = $("<li><p>内容</p><p><span>IP地址： </span><span>评论时间： </span></p></li>");
                        $("#TxtComment").append(newComment);
                        alert("评论发表成功！");
                    } else if (data=="forbid") {
                        alert("评论请文明用语！");
                    } else {
                        alert("发表评论时出错！");
                    }
                });
            });
        });
    </script>
    <style type="text/css">
        #TextArea1 {
            height: 66px;
            width: 345px;
        }

        #TxtComment {
            width: 329px;
            height: 45px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData" TypeName="_20160627AJAX项目学习.DAL.DataSetPostTableAdapters.T_PostTableAdapter"></asp:ObjectDataSource>
            <asp:Repeater ID="Repeater1" runat="server" DataSourceID="ObjectDataSource1" OnItemCreated="Repeater1_ItemCreated">
                <HeaderTemplate>
                    <ul id="ulComment">
                </HeaderTemplate>
                <ItemTemplate>
                    <li>
<%--                        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>--%>
                        <p><%# Eval("Message") %></p>
                        <p><span>IP地址：<%# Eval("IPAddr") %></span><span>评论时间：<%# Eval("PostDate") %></span></p>
                    </li>
                </ItemTemplate>
                <FooterTemplate></ul></FooterTemplate>
            </asp:Repeater>
        </div>
        <!-----AJAX----->
        <div>
            <p>
                <textarea id="TxtComment"></textarea>
            </p>
            <p>
                <input id="BtnPost" type="button" value="提交" />
            </p>
        </div>
    </form>
</body>
</html>
